// sub_minsheng_sjts/sjts_batch/sjts_batch.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchValue:'',
    roleType: '',
    pageNum: 1,
    repeat: 1,
    batchNum: '',
    batchType: '',
    dataList: [],
    active: '',
    show: false,
    value2: '',
    zflxType: '',
    option2: [
    ],
  },
  toDetail(e){
    console.log(e,'ee')
    wx.navigateTo({
      url: `/pages/mapDetail/mapDetail?corpKey=${e.currentTarget.dataset.corpcredit}`,
    });
  },
  goSearch() {
    console.log('点击了')
    this.setData({
      pageNum: 1,
      repeat: 1,
      dataList: []
    })
    this.scrollBottom()
  },
  searchChange(e) {
    console.log(e, 'eee')
    this.setData({
      searchValue: e.detail
    })
  },
  async getList() {
    let params = {
      batchNum: this.data.batchNum,
      batchType: this.data.batchType,
      pageNum: this.data.pageNum,
      pageSize: 12,
      status: this.data.zflxType,
      corpName: this.data.searchValue,
    }
    const res = await getApp().globalData.request(
      "/businessPush/getBatchBusinessManage", params,
      "POST"
    )
    console.log(params, res, '接口返回的值')
    let list = res.data.list
    list.forEach(element => {
      this.data.dataList.push(element)
    });
    this.setData({
      dataList: this.data.dataList,
    })
    this.data.pageNum = this.data.pageNum + 1
  },
  scrollBottom() {

    if (this.data.repeat == this.data.pageNum) {
      this.data.repeat = this.data.repeat + 1
      this.getList()
    }
  },
  onSwitch1Change2(e) {
    console.log(e, '22')
    this.setData({
      value2: e.detail,
      dataList: [],
      pageNum: 1,
      repeat: 1,
      zflxType: e.detail
    })
    this.scrollBottom()
  },
  showPopup(e) {
    // this.setData({ show: true });
    console.log(e, 'eee')
    wx.navigateTo({
      url: `/sub_minsheng_sjts/sjts_feedback/sjts_feedback?corpCredit=${e.currentTarget.dataset.corpcredit}&&status=${e.currentTarget.dataset.status}&&remark=${e.currentTarget.dataset.remark}`,
    })
  },
  async getRole() {
    const res = await getApp().globalData.request(
      "/businessPush/getCommissionerRole", {},
      "POST"
    )
    console.log(res, '获取角色')
    if (res.data == 1) {
      this.data.roleType = '管理员'
    } else if (res.data == 2) {
      this.data.roleType = '线下客户经理'
      this.data.value2 = '31'
      this.data.option2 = [
        { text: '全部', value: '31' },
        { text: '未接通', value: '12' },
        { text: '不需要', value: '13' },
        { text: '他行开户', value: '14' },
        { text: '继续跟进', value: '15' },
        { text: '已尽调', value: '16' },
        { text: '账户已交付', value: '17' }]
    } else if (res.data == 3) {
      console.log('外呼员')
      this.data.roleType = '线上外呼员'
      this.data.value2 = '30'
      this.data.option2 = [{ text: '全部', value: 30 },
      { text: '已派单', value: 10 },
      { text: '已接通', value: 2 },
      { text: '不需要', value: 3 },
      { text: '他行开户', value: 4 },
      { text: '继续跟进', value: 5 },
      { text: '非企业关键人', value: 6 },
      { text: '未接通', value: 7 },
      { text: '停机', value: 8 },
      { text: '空号', value: 9 }]
    }

    this.setData({
      roleType: this.data.roleType,
      option2: this.data.option2,
      value2: this.data.value2
    })
  },
  goClose() {
    this.setData({ show: false });
  },
  goWander() {
    wx.navigateTo({
      url: "/sub_minsheng_sjts/sjts_wander/sjts_wander",
    })
  },

  onChange(e) {
    console.log(e, 'eee')
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options,'optionsoptions')
    wx.setNavigationBarTitle({
      title: options.batchNum?'新设企业-第'+options.batchNum+'批次':'新设企业', // 页面标题为传递的标题或默认标题
      success: function () {
        // 设置成功的回调函数
        console.log('标题设置成功');
      },
      fail: function () {
        // 设置失败的回调函数
        console.log('标题设置失败');
      }
    });

    // this.getRole()
    // this.setData({
    //   batchNum: options.batchNum,
    //   batchType: options.batchType
    // })
    // this.scrollBottom()
    // console.log('问题')
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];
    //当前页的options，啥意思呢，就是你可能某个函数需要刷新，但是他的参数正好是传过来的参数
    console.log(currPage.options, '是啥');
    this.setData({
      pageNum: 1,
      repeat: 1,
      batchNum: currPage.options.batchNum,
      batchType: currPage.options.batchType,
      dataList: []
    })
    this.getRole()

    this.scrollBottom()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})